package com.muye.constant;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.os.Environment;
import android.util.SparseArray;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.widget.TextView;
import android.widget.Toast;

import com.muye.dianli.R;
import com.muye.dianli.activity.LoginActivity;
import com.muye.field.HomePageListData;
import com.muye.field.ShoppingCartField;

/**
 * 常量类
 * 
 * @author TangChao
 * 
 */
public class C
{
	/**
	 * 标签
	 */
	public static String TAG = "TANG_CHAO";
	
	/**
	 * appId
	 */
	public static String APPID = "3";
	
	/**
	 * 请求常数
	 */
	public static final String CONSTANT = "04dde9f462255fe14b5160bbf2acffe8";
	
	/**
	 * 请求缓冲提示框
	 */
	private static AlertDialog customProgressDialog;
	
	/**
	 * App图片缓存路径
	 */
	public final static String FILE_PATH = Environment.getExternalStorageDirectory() + "/DianLi";
	
	/**
	 * 购物车数据
	 */
	public static List<SparseArray<ShoppingCartField>> SHOPPING_CART_DATA;
	
	/**
	 * 打开请求缓冲提示框
	 * 
	 * @param context
	 * @param onKeyListener
	 * @param object
	 */
	public static void openPragressDialog(Context context, OnKeyListener onKeyListener, Object object)
	{
		Animation animation = AnimationUtils.loadAnimation(context, R.anim.request_dialog_show_animation);
		BounceInterpolator bounceInterpolator = new BounceInterpolator();
		animation.setInterpolator(bounceInterpolator);
		if (customProgressDialog != null && customProgressDialog.isShowing())
		{
			return;
		}
		customProgressDialog = new AlertDialog.Builder(context).create();
		customProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		customProgressDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		customProgressDialog.show();
		customProgressDialog.getWindow().setContentView(R.layout.pragress_dialog_layout);
		customProgressDialog.setCancelable(true);
		if (onKeyListener != null)
		{
			customProgressDialog.setOnKeyListener(onKeyListener);
		}
		final TextView infoView = (TextView) customProgressDialog.findViewById(R.id.dialogInfo);
		infoView.setAnimation(animation);
		if (object instanceof Integer)
		{
			infoView.setText((Integer) object);
		}
		else if (object instanceof String)
		{
			infoView.setText((String) object);
		}
	}
	
	/**
	 * 关闭请求缓冲提示框
	 */
	public static void closePragressDialog()
	{
		if (customProgressDialog != null)
		{
			customProgressDialog.cancel();
			customProgressDialog = null;
		}
	}
	
	/**
	 * 显示Toast
	 * 
	 * @param context
	 * @param str
	 */
	public static void showToast(Context context, Object object)
	{
		if (object instanceof Integer)
		{
			Toast.makeText(context, (Integer) object, Toast.LENGTH_SHORT).show();
		}
		else if (object instanceof String)
		{
			Toast.makeText(context, (String) object, Toast.LENGTH_SHORT).show();
		}
		
	}
	
	/**
	 * 检测是否登陆
	 */
	public static boolean isLogin(Context context)
	{
		if (ConstantPersonalInfo.uid.equals("") || ConstantPersonalInfo.uid == null)
		{
			Intent intent = new Intent(context, LoginActivity.class);
			context.startActivity(intent);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	/**
	 * 账户信息XML
	 */
	public static String ACCOUNT_INFO = "ACCOUNT_INFO";
	
	/**
	 * 用户名
	 */
	public static String USER_NAME = "USER_NAME";
	
	/**
	 * 密码
	 */
	public static String PASSWORD = "PASSWORD";
	
	/**
	 * 首页数据
	 */
	public static List<List<HomePageListData>> MAIN_DATA;
}
